﻿@model PagedList.IPagedList<FTBS.Models.Entities.User>
@using PagedList.Mvc;
<link href="~/Content/PagedList.css" rel="stylesheet" type="text/css" />

@{
    ViewBag.Title = "Quản lí nhân viên";
    Layout = "~/Views/Shared/_AdminLayout.cshtml";
    var isSortDes = (bool)ViewBag.IsSortDes;
}

<legend style="margin-top: 10px">QUẢN LÝ NHÂN VIÊN</legend>
<p>
    @Html.ActionLink("Thêm nhân viên", "Create")
</p>

<div>
    <div>
        @using (Html.BeginForm("Index", "Staff", FormMethod.Get))
        {
            <p>
                Tìm kiếm: @Html.TextBox("SearchString", ViewBag.CurrentFilter as string)
                <input class="inverse" type="submit" value="Tìm" />
            </p>
        }
    </div>

    <div>
        <table class="table striped bordered hovered" width="100%">
            <tr>
                <th>
                    @Html.ActionLink("Tên nhân viên", "Index", new { sortOrder = ViewBag.NameSortParm, isSortDescending = isSortDes })
                </th>
                <th>
                    @Html.ActionLink("Email", "Index", new { sortOrder = "email_desc", isSortDescending = isSortDes })
                </th>
                <th>
                    @Html.ActionLink("Số điện thoại", "Index", new { sortOrder = "phoneNumber_desc", isSortDescending = isSortDes })   
                </th>
                <th>
                    @Html.ActionLink("Trạng thái", "Index", new { sortOrder = "status_desc", isSortDescending = isSortDes })
                </th>
                <th></th>
                <th></th>
                <th></th>
            </tr>
            @foreach (var item in Model)
            {
                <tr>
                    <td style="width: 20%;">
                        @Html.DisplayFor(modelItem => item.FullName)
                    </td>
                    <td style="width: 25%;">
                        @Html.DisplayFor(modelItem => item.Email)
                    </td>
                    <td style="width: 10%;">
                        @Html.DisplayFor(modelItem => item.PhoneNumber)
                    </td>

                    @if (@item.IsActive.ToString().Trim().Equals("True"))
                    {
                        <td style="width: 15%;">Đã kích hoạt
                        </td>
                        <td style="width: 10%;">
                            @Html.ActionLink("Khoá", "Deactive", new { id = item.UserName })
                        </td>
                    }
                    @if (@item.IsActive.ToString().Trim().Equals("False"))
                    {
                        <td style="width: 15%;">Đã khoá
                        </td>
                        <td style="width: 10%;">
                            @Html.ActionLink("Kích hoạt", "Active", new { id = item.UserName })
                        </td>
                    }

                    <td style="width: 15%;">
                        @Html.ActionLink("Sửa", "Edit", new { id = item.UserName }) | 
                        @Html.ActionLink("Chi tiết", "Detail", new { id = item.UserName })
                    </td>
                    <td style="width: 5%">
                        @using (Html.BeginForm("Delete", "Staff", new { id = item.UserName }, FormMethod.Post,
                                       new { onsubmit = "return confirm('Bạn có chắc chắn muốn xóa nhân viên này không?');" }))
                        {
                            @Html.HttpMethodOverride(HttpVerbs.Delete)
                            <button type="submit" style="background: none; border: none; display: inline; font: inherit; margin: 0; padding: 0; outline: none; outline-offset: 0; /* Additional styles to look like a link */
                                                                                                                                         color: #2e92cf; cursor: pointer; text-decoration: underline;">
                                Xóa</button>
                        }
                    </td>
                </tr>
            }
        </table>
    </div>

    <div style="float:right">
        <br />
        <div style="margin-left:34px">
            Trang @(Model.PageCount < Model.PageNumber ? 0 : Model.PageNumber) của @Model.PageCount trang
        </div>
        <div style="margin-right:-20px">
            @Html.PagedListPager(Model, page => Url.Action("Index",
            new { page, sortOrder = ViewBag.CurrentSort, currentFilter = ViewBag.CurrentFilter }))
        </div>
    </div>

</div>


